#!/bin/bash

sleep 30
#gcc a.c
#cat ./a.log
#exit 0
HOME=/root
flag=0
CPATH=`pwd`

product=${JOB_NAME##*-}
if [ "x$product" == "xdocker" ];then
    projects_list=service_list_ARM_docker.xml
elif [ "x$product" == "xkernel" ];then
    projects_list=service_list_ARM_kernel.xml
elif [ "x$product" == "xhack" ];then
    projects_list=service_list_ARM_hack.xml
else
    projects_list=service_list_ARM.xml
fi
#obs_meta_dir="$CPATH/../../../../../obs_meta"
projects=`cat $projects_list | grep 'project name' | awk -F'"' '{print $2}' | sort | uniq`
rm -rf buildlog && mkdir -p buildlog

#exclude_packages="crash makedumpfile-3.10.0_x86_64_standard"
#exclude_packages="kernel kernel-nic kernel_aarch64 kernel_aarch64_for_storage kernel_for_dorado kernel_for_microvm kernel_for_storage"
for project in `echo $projects`
do
    #echo "xdf====$project"
    osc repos $project > repos.list
    #Recently,only check aarch64
    sed  -i '/standard_x86_64/d' repos.list
    sed  -i '/standard_i686/d' repos.list
    while read repo_arch
    do
        repo=`echo "$repo_arch" | awk '{print $1}'`
        arch=`echo "$repo_arch" | awk '{print $2}'`
        #echo "xdf===$repo, arch===$arch, repo_arch=====$repo_arch"
        for package in `osc ls $project`
        do
            if osc cat $project $package _service | grep '/open_source/' &> /dev/null; then
                flag=1
            elif osc cat $project $package _service | grep '/open-source/' &> /dev/null;then
                flag=2
            elif [ x$package == xshadow-utils-euler -o  x$package == xirqbalance -o  x$package == xcpulimit -o x$package == xkillproc -o x$package == xvos -o x$package == xos-test ];then
                flag=3
            fi
            if [ $flag -eq 0 ]
            then
                if ! osc r $project $package -r $repo -a $arch | grep -w 'disabled' 2> /dev/null; then
                    osc remotebuildlog $project $package $repo $arch -s > buildlog/${project}_${package}_${repo}_${arch} 2> /dev/null
                fi
            else
                flag=0
            fi
            #echo "$project=$package=$repo=$arch"
            #osc remotebuildlog $project $package $repo $arch -s > buildlog/${project}_${package}_${repo}_${arch} 2> /dev/null
        done
    done < repos.list
done
#exit 0
rm -f log_all
cd buildlog
for file in `ls`
do
    while read line
    do
        echo "$file===$line" >> ../log_all
    done < $file
done
cat ../log_all
